package com.maijinjie.common.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * Action 基本类
 * @version 1.0
 * @author GhostarX ( 王欣逸 ) 100992995@qq.com
 * @data 2013-8-13 上午11:54:01
 */
public class BaseAction {
	/** 日志类 */
	public Logger log = Logger.getLogger(this.getClass());
	/**
	 * 输出内容
	 * @param html
	 * @param response
	 * @throws IOException
	 */
	public void write(String html, HttpServletResponse response) throws IOException{
		PrintWriter writer = null;;
		try {
			writer = response.getWriter();
			writer.write(html);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
			throw e;
		} finally {
			if(null!=writer){
				writer.close();
			}
		}
	}
	/**
	 * 输出HTML代码
	 * @param html html代码
	 * @param response
	 * @throws IOException 
	 */
	public void writeHTML(String html, HttpServletResponse response) throws IOException{
		response.setContentType("text/html; charset=UTF-8");
		write(html, response);
	}
	/**
	 * 输出TEXT代码
	 * @param html html代码
	 * @param response
	 * @throws IOException 
	 */
	public void writeTEXT(String html, HttpServletResponse response) throws IOException{
		response.setContentType("text/plain; charset=UTF-8");
		write(html, response);
	}
}
